<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>日志展示页面</title>
    <!-- 引入 jQuery -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style>
        table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
    <h1>日志列表</h1>
    <table id="logs-table">
        <thead>
            <tr>
                <th>ID</th>
                <th>应用名称</th>
                <th>日志级别</th>
                <th>请求方法</th>
                <th>请求路径</th>
                <th>日志内容</th>
                <th>创建时间</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>

    <script>
        $(document).ready(function() {
            // 发起 AJAX 请求获取日志数据
            $.ajax({
                url: '/api/logs',
                method: 'GET',
                success: function(data) {
                    // 遍历日志数据并添加到表格中
                    data.forEach(function(log) {
                        $('#logs-table tbody').append(`
                            <tr>
                                <td>${log.id}</td>
                                <td>${log.app}</td>
                                <td>${log.level}</td>
                                <td>${log.method}</td>
                                <td>${log.path}</td>
                                <td>${log.message}</td>
                                <td>${log.created_at}</td>
                            </tr>
                        `);
                    });
                },
                error: function(error) {
                    console.error('获取日志失败:', error);
                }
            });
        });
    </script>
</body>
</html>